<?php

namespace app\index\model;

use think\Model;

class Process extends BaseModel
{

    public static function getByOnline()
    {
        return self::where('onlineswitch', 1)->order(['recommendswitch desc', 'weigh desc'])->select();
    }

    public static function getAll()
    {
        $resources = self::getByOnline();
        if (!$resources) {
            return [];
        }
        $sources = array_values(array_unique(array_column($resources, 'sourcedata')));
        $data = [];
        foreach ($sources as $s) {
            foreach ($resources as $val) {
                if ($s == $val['sourcedata']) {
                    $data[$s][] = $val;
                }
            }
        }
        foreach ($data as &$val) {
            $count = 0;
            $k = 0;
            $arr = [];
            foreach ($val as $v) {
                if ($count >= 14) {
                    $k++;
                    $count = 0;
                }
                $count++;
                $arr[$k][] = $v;
            }
            $val = $arr;
        }
        return $data;
    }
}
